﻿using AutoMapper;
using MediatR;
using Microsoft.AspNetCore.Components.Forms;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using RearLivestock.Common.Domains.hq;
using RearLivestock.Common.Domains.wbx;
using RearLivestock.Common.Dtos;
using RearLivestock.RBAC.Api.Application.hqApplication.Commands.Enterprisess;
using RearLivestock.RBAC.Api.Application.hqApplication.Commands.Departmentss;
using RearLivestock.RBAC.Api.Application.wbxApplication.Commands.Role;
using RearLivestock.RBAC.ErrorCodeEnum;

namespace RearLivestock.RBAC.Api.Controllers.hq
{
    /// <summary>
    /// hq企业管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class EnterpriseController : ControllerBase
    {
        private readonly IMediator imediator;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="imediaManager"></param>
        public EnterpriseController(IMediator imediator)
        {
            this.imediator = imediator;
        }

        /// <summary>
        /// 添加企业
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> AddEnterprise(AddEnterpriseCommand command)
        {
            return await imediator.Send(command);
        }

        /// <summary>
        /// 企业显示
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result<PageResultDto<Enterprise>>> ShowEnterprice(ShowEnterpriceCommand request)
        {
            return await imediator.Send(request);

        }
        /// <summary>
        /// 上传图片
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult UploadFilest(IFormFile file)
        {
            string fileName = file.FileName;
            string path = Directory.GetCurrentDirectory() + @"\wwwroot\Images\" + fileName;
            using (FileStream fs = new FileStream(path, FileMode.Create))
            {
                file.CopyTo(fs);
                fs.Flush();
            }
            string url = "/Images/" + fileName;
            return Ok(url);

        }
       

    }
}
